package com.zhanghp.class003;

/**
 * @author zhanghp
 * @since 2024/3/20 15:25
 */
public class TestBinary {
    public static void main(String[] args) {
        // ~(a - 1) = ~a + 1
        int a = 2;
        System.out.println(~a + 1);
        System.out.println(~(a - 1));
        System.out.println(-a);
test();
     int b = Integer.MIN_VALUE;
        System.out.println(~b + 1);
        System.out.println(~(b - 1));
        System.out.println(-b);
        System.out.println((1 << 31) - 1);
    }

    public static void test(){
        int test_time = 1_000_000;
        System.out.println("测试开始");
        for (int i = 0; i < test_time; i++) {
            int a = ((int) (Math.random() * Integer.MAX_VALUE)) + 1;
            if ((~a + 1) != (~(a - 1))) {
                System.out.println(a);
                break;
            }
        }
        System.out.println("测试结束");
    }

    public static void printBinary(int i){
        for (int j = 31; j >= 0; j--) {
            System.out.print((1 & i >> j) == 1 ? 1 : 0);
        }
        System.out.println();
    }
}
